class Solution {
    public int calPoints(String[] operations) {
        int sum = 0 ;
        int nums[] = new int[operations.length] ;
        int usedSize = 0 ;
        for(int i = 0 ; i < operations.length ; i++){
            if(operations[i].equals("C")){
                usedSize -- ;
            }else if(operations[i].equals("D")){
                nums[usedSize] = nums[usedSize -1 ] * 2 ;
                usedSize ++ ;
            }else if(operations[i].equals("+")){
                nums[usedSize] = nums[usedSize - 1] +
                        nums[usedSize - 2];
                usedSize ++ ;
            }else{
                nums[usedSize++] = Integer.parseInt(operations[i]);
            }
        }
        for(int i = 0 ; i< usedSize; i++){
            sum += nums[i];
        }
        return sum ;
    }
}